package com.ddyx.common.utils.token;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.Random;

/**
 * token生成
 * 
 */
public class TokenUtil {
	public static String generateTokenString() {
		// StringBuilder sb = new StringBuilder();
		// sb.append(new SimpleDateFormat("yyMMddHHmmSS").format(new Date()));
		// sb.append(ValidateCode.generateTextCode(1, 5, null));
		// return sb.toString();
		return RandomStringUtils.randomAlphanumeric(15);
	}

	public static String getRandomStringByLength(int length) {
		String base = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		Random random = new Random();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		System.out.println(generateTokenString());
		System.out.println(RandomStringUtils.randomAlphanumeric(15));
		System.out.println(getRandomStringByLength(15));
	}
}
